iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 17
0

RestfulAPI Class

public class RetrofitClient {
    private static Retrofit retrofit = null;
    OkHttpClient client = new OkHttpClient();
    //    public final String BASE_URL = "http://braindna.co/";
    public final String URL = "http://54.174.149.227:8080";
    //  http://54.174.149.227:8080/calculate16Personality


    public APIService getAPIService(Context context) {

        return getClient(URL, context).create(APIService.class);
    }


    public OkHttpClient getBuilder(Context context) {
        return new OkHttpClient.Builder()
//                .addInterceptor(new AddCookiesInterceptor(context))  // VERY VERY IMPORTANT
//                .addInterceptor(new ReceivedCookiesInterceptor(context))  // VERY VERY IMPORTANT
                .build();


    }

    public Retrofit getClient(String baseUrl, Context context) {

        return new Retrofit.Builder()
                .baseUrl(baseUrl)
                .client(getBuilder(context))
                .addConverterFactory(GsonConverterFactory.create())
                .build();


    }

    public final String BASE_URL = "http://braindna.co/";

    public APIService getService(Context context) {

        return getTwiceClient(BASE_URL, context).create(APIService.class);
    }


    public OkHttpClient getTwiceBuilder(Context context) {
        return new OkHttpClient.Builder()
                .addInterceptor(new AddCookiesInterceptor(context))  // VERY VERY IMPORTANT
                .addInterceptor(new ReceivedCookiesInterceptor(context))  // VERY VERY IMPORTANT
                .build();


    }

    public Retrofit getTwiceClient(String baseUrl, Context context) {

        return new Retrofit.Builder()
                .baseUrl(baseUrl)
                .client(getTwiceBuilder(context))
                .addConverterFactory(GsonConverterFactory.create())
                .build();


    }
}

上一篇
[Day16] SQLite-03
下一篇
[Day18]MediaRecorder
系列文
Java 與 Kotlin 入門30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言